package com.beep.erp.model.mine;


import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.beep.erp.Constants;
import com.beep.erp.R;
import com.beep.erp.common.base.BaseFragment;
import com.beep.erp.common.base.simpleactivity.SimpleBackActivity;
import com.beep.erp.common.base.simpleactivity.SimpleBackPage;
import com.beep.erp.common.utils.SPUtils;
import com.beep.erp.common.utils.ToastUtils;
import com.beep.erp.common.utils.ToolsUtils;
import com.beep.erp.model.earlystage.scan.ScanActivity;
import com.beep.erp.model.login.LoginActivity;
import com.beep.erp.model.stock.StockAdapter;
import com.beep.erp.model.stock.StockContract;
import com.beep.erp.model.stock.StockModel;
import com.beep.erp.model.stock.StockPresenter;
import com.beep.erp.model.stockIn.StockInListActivity;
import com.beep.erp.model.transfer.TransferActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.beep.erp.AppContext._context;

/**
 * A simple {@link Fragment} subclass.
 */
public class MineFragment extends BaseFragment<StockPresenter, StockModel> implements StockContract.View {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appbar_layout)
    AppBarLayout appbarLayout;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.btn_quit)
    AppCompatButton btnQuit;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;

    private SPUtils spUtils;
    private String userName = "";

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initView(View view) {
        tvTitle.setText(R.string.person_center);
        spUtils = new SPUtils(_context, Constants.EXTRA_LOGIN_SP);
    }

    @OnClick({R.id.btn_quit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_quit:
                userName = spUtils.getString(Constants.USER_NAME);
                if (ToolsUtils.isEmpty(userName)) {
                    LoginActivity.start(getActivity());
                } else {
                    spUtils.clear();
                    spUtils.putBoolean(Constants.EXTRA_ISLOGIN, false);
                    LoginActivity.start(getActivity());
                }
                break;
        }
    }

    @Override
    protected void lazyLoad() {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(String message) {
        ToastUtils.showShort(message);
    }

    @Override
    public void onResume() {
        super.onResume();
        userName = spUtils.getString(Constants.USER_NAME);
        tvUserName.setText(userName);
        btnQuit.setText(ToolsUtils.isEmpty(userName) ? "登录" : "退出");
    }

}
